<?php
namespace app\common\controller;
use think\Controller;
use think\facade\Cache;
use base\BaseMethod;
//use base\service\MailerApi;
require_once base_path().'/extend/lib/phpMailer/class.phpmailer.php';
require_once base_path().'/extend/lib/phpMailer/class.smtp.php';


//邮箱
class Mailer extends Controller 
{
	
	/**
	*  common/mailer/send
	* 发送邮件
	*/
	public function send($address='',$title='',$body=''){
		if(!$address || !$title || !$body){
			return $this->ReError('参数错误');	
		}
		try {
			$mail = new \PHPMailer(true); //建立邮件发送类
			$mail->CharSet = "UTF-8";//设置信息的编码类型
			
			$receiving_address = $address;//收件人地址
			$receiving_name = "";//收件人地址
			
			$mail->IsSMTP(); // 使用SMTP方式发送
			$mail->Host = "smtp.qq.com"; //使用qq邮箱服务器
			$mail->SMTPAuth = true; // 启用SMTP验证功能
			$mail->SMTPSecure = "ssl";
			$mail->SMTPKeepAlive = true;   
			$mail->Username = "420656345@qq.com"; //你的qq邮箱账号
			$mail->Password = "fvraiyscnxibcadi"; // qq邮箱密码
			$mail->Port = 465;	//邮箱服务器端口号
			
			$mail->From = "420656345@qq.com"; //邮件发送者email地址
			$mail->FromName = "";//发件人名称
			$mail->AddAddress("$receiving_address","$receiving_name"); //收件人地址
			
			//$mail->AddAttachment("D:\abc.txt"); // 添加附件(注意：路径不能有中文)
			$mail->IsHTML(true);//是否使用HTML格式
			$mail->Subject = "$title"; //邮件标题
			$mail->Body = "$body"; //邮件内容，上面设置HTML，则可以是HTML
			
			if (!$mail->Send()) {
				return BaseMethod::ReError( $mail->ErrorInfo);	
			}else{
				return BaseMethod::ReSucess('','发送成功！');	
			}
		} catch (\Exception $e) {
			return BaseMethod::ReError($e->getMessage());	
		}
	}
}



